from fastapi import Request

from service import UserService, SongService
from common.result.Result import Result
from common.enum import BaseEnum
from util.log import Log


async def GetSongSearchHistory(req: Request):
    try:
        token = req.headers.get("token")
        user = await UserService.getUserByToken(token)
        if user == None:
            return Result.error(BaseEnum.USER_NOT_EXISTS_ERROR)
        
        history = await SongService.getSearchHistoryByUserId(user.id)

        return Result.success(history)
    except Exception as e:
        Log.error('获取 song 搜索历史异常', e)
        return Result.error(BaseEnum.SERVICE_ERROR)



